package com.lxp.userms.service.impl;

import com.lxp.userms.entity.ExpertAnswer;
import com.lxp.userms.mapper.ExpertAnswerMapper;
import com.lxp.userms.service.ExpertAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExpertAnswerServiceImpl implements ExpertAnswerService {

    @Autowired
    private ExpertAnswerMapper answerMapper;

    @Override
    @Transactional
    public int askQuestion(ExpertAnswer answer) {
        return answerMapper.insertAnswer(answer);
    }

    @Override
    public List<ExpertAnswer> getAllAnswers() {
        return answerMapper.selectAllAnswers();
    }

    @Override
    public List<ExpertAnswer> getAnswersByUserId(int userId) {
        return answerMapper.selectAnswersByUserId(userId);
    }

    @Override
    public List<ExpertAnswer> getAnswersByExpertId(int expertId) {
        return answerMapper.selectAnswersByExpertId(expertId);
    }

    @Override
    @Transactional
    public int replyToQuestion(ExpertAnswer answer) {
        return answerMapper.updateAnswer(answer);
    }
    @Override
    @Transactional
    public int insertNewAnswer(ExpertAnswer answer) {
        return answerMapper.insertAnswer(answer); // 确保 Mapper 中有对应方法
    }
    @Override
    public ExpertAnswer getAnswerByQuestionId(int questionId) {
        return answerMapper.selectAnswerByQuestionId(questionId);
    }

    @Override
    @Transactional
    public int deleteAnswersByQuestionId(int questionId) {
        return answerMapper.deleteAnswersByQuestionId(questionId);
    }
}